package com.yserp.project.erp.basic.supplier.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yserp.common.constant.Constants;
import com.yserp.common.utils.mybatis.MybatisPlusUtil;
import com.yserp.project.erp.basic.supplier.domain.BasisSupplier;
import com.yserp.project.erp.basic.supplier.mapper.BasisSupplierMapper;
import com.yserp.project.erp.basic.supplier.service.IBasisSupplierService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 供应商管理Service业务层处理
 *
 * @author yserp
 * @date 2022-06-29
 */
@Service
public class BasisSupplierServiceImpl extends ServiceImpl<BasisSupplierMapper, BasisSupplier> implements IBasisSupplierService {
    @Resource
    private BasisSupplierMapper basisSupplierMapper;


    /**
     * 查询供应商管理列表
     *
     * @param basisSupplier 供应商管理
     * @return 供应商管理
     */
    @Override
    public List<BasisSupplier> selectBasisSupplierList(BasisSupplier basisSupplier) {
        QueryWrapper<BasisSupplier> queryWrapper = new QueryWrapper<>();
        MybatisPlusUtil.notNullField(basisSupplier, queryWrapper);
        return basisSupplierMapper.selectList(queryWrapper);
    }


    @Override
    public String checkSupplierCodeUnique(String supplierCode) {
        String flag = Constants.NAME_UNIQUE;
        int count = basisSupplierMapper.selectCount(new QueryWrapper<BasisSupplier>().eq("supplier_code", supplierCode));
        if (count > 0) {
            flag = Constants.NAME_NOT_UNIQUE;
        }
        return flag;
    }
}
